<!-- 游戏编辑弹窗 -->
<template>
  <el-dialog
    :title="isUpdate ? '修改商户模版' : '添加商户模版'"
    :visible="visible"
    width="700px"
    :destroy-on-close="true"
    :lock-scroll="false"
    @update:visible="updateVisible"
    append-to-body
    :close-on-click-modal="false"
  >
    <el-form ref="form" :model="form" :rules="rules" label-width="150px">
      <el-form-item label="参数名称:" prop="name">
        <el-input v-model="form.name" placeholder="请输入参数名称" clearable />
      </el-form-item>
      <el-form-item label="KEY:" prop="key">
        <el-input v-model="form.key" placeholder="请输入KEY" clearable />
      </el-form-item>
      <el-form-item label="是否必填:" prop="is_null">
        <el-radio-group v-model="form.is_null">
          <el-radio-button :label="0">否</el-radio-button>
          <el-radio-button :label="1">是</el-radio-button>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="是否绑定字段:" prop="is_account">
        <el-radio-group v-model="form.is_account">
          <el-radio-button :label="0">否</el-radio-button>
          <el-radio-button :label="1">是</el-radio-button>
        </el-radio-group>
        <span>（与技术确认后更改）</span>
      </el-form-item>
      <el-form-item label="填写类型:" prop="type">
        <el-radio-group v-model="form.type">
          <el-radio-button :label="1">input</el-radio-button>
          <el-radio-button :label="2">textarea</el-radio-button>
        </el-radio-group>
      </el-form-item>
    </el-form>
    <div slot="footer">
      <el-button @click="updateVisible(false)">取消</el-button>
      <el-button type="primary" @click="save" :loading="loading"
        >保存
      </el-button>
    </div>
  </el-dialog>
</template>

<script>
// import uploadImageFin from '../../../components/uploadImageFin.vue'

export default {
  name: 'PaymentAccountEdit',
  props: {
    // 弹窗是否打开
    visible: Boolean,
    // 修改回显的数据
    data: Object,
    pay_way_id: String
  },
  //   components: { uploadImageFin },
  data() {
    return {
      // 表单数据
      form: Object.assign({}, this.data),
      where: {},
      // 表单验证规则
      rules: {
        name: [{ required: true, message: '请输入参数名称', trigger: 'blur' }],
        key: [{ required: true, message: '请输入KEY', trigger: 'blur' }]
        // is_null: [{ required: true, message: '请选择', trigger: 'change' }],
        // is_account: [{ required: true, message: '请选择', trigger: 'change' }],
        // type: [{ required: true, message: '请选择', trigger: 'change' }]
      },
      // 提交状态
      loading: false,
      // 是否是修改
      isUpdate: false
    }
  },
  watch: {
    visible(val) {
      if (val) {
        if (this.data) {
          this.form = Object.assign({}, this.data)
          this.isUpdate = true
        } else {
          this.form = {
            is_null: 1,
            is_account: 0,
            type: 1
          }
          this.isUpdate = false
        }
      }
    }
  },
  methods: {
    /* 保存编辑 */
    // changeAppid(val) {
    //   this.$set(this.form, 'app_id', val)
    //   console.log(this.form)
    // },
    save() {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          this.loading = true
          this.$http
            .post('/paywaytemplate/edit', {
              ...this.form,
              pay_way_id: this.pay_way_id
            })
            .then((res) => {
              this.loading = false
              if (res.data.code === 0) {
                this.$message.success(res.data.msg)
                if (!this.isUpdate) {
                  this.form = {}
                }
                this.updateVisible(false)
                this.$emit('done')
              } else {
                this.$message.error(res.data.msg)
              }
            })
            .catch((e) => {
              this.loading = false
              this.$message.error(e.message)
            })
        } else {
          return false
        }
      })
    },
    /* 更新visible */
    updateVisible(value) {
      this.$emit('update:visible', value)
    }
  }
}
</script>

<style scoped>
::v-deep .room_add_img {
  margin: 0px !important;
}
::v-deep .finish_room2 .room_img {
  margin: 0px !important;
}
</style>
